package net.csdn.business.mirror.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.csdn.business.mirror.service.ScheduleTaskImplement;
import net.csdn.business.mirror.service.impl.ScheduleTaskMirrorImplement;
import net.csdn.business.mirror.service.impl.ScheduleTaskSyncGithubImplement;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

public class ScheduleTaskEnum {

    @AllArgsConstructor
    public enum Status {
        _0(0, "无效"),
        _1(1, "有效");
        public int code;
        private String desc;
    }

    @Getter
    @AllArgsConstructor
    public enum Name {
        MIRROR("mirror", ScheduleTaskMirrorImplement.class, "镜像"),
        SYNC_GITHUB("sync_github", ScheduleTaskSyncGithubImplement.class, "同步github数据"),
        ;

        private String type;
        private Class<? extends ScheduleTaskImplement> scheduleTaskImplementService;
        private String title;

        public static final Map<String, Name> MAP = Maps.newHashMap();

        static {
            for (Name name : Name.values()) {
                MAP.put(name.type, name);
            }
        }

        public static Name parse(String name) {
            if (StringUtils.isBlank(name)) {
                return null;
            }
            return MAP.get(name);
        }
    }
}
